Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern builder #1538

Closed
wants to merge 20 commits into from
Closed

Conversation

RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented Aug 22, 2018

This PR is an implementation of #1476.

I decided to make a new namespace Prism.patterns (*hint* *hint* #1494) to keep things organized because build doesn't really belong in any of the other namespaces.

The validation method of the base pattern and replacements is located in a new file called tests/helper/prism-core-tester.js.
This file's purpose is to add testing functionality to existing Prism methods only when running npm test. This has the following advantages:

  • prism-core.js stays small but still validates on all tested components.
  • The validation is not done on our client's computers.

Maybe we should make this a resource (#1539)?


Btw. This and #1537 go together really well.

@RunDevelopment
Copy link
Member Author

It intrigues me that the build failed despite the fact that I only changed some comments...

It seems like the npm install -g gulp command took longer than 10 minutes. How can that be?
Node v6 took each about 7 minutes for npm install and nom install -g gulp.

@RunDevelopment
Copy link
Member Author

Now it worked again.
And it took at most 20 seconds for the npm install commands.

@mAAdhaTTah
Copy link
Member

Travis does weird stuff sometimes. I wouldn't worry too much about it.

@RunDevelopment RunDevelopment mentioned this pull request Jan 1, 2019
@RunDevelopment
Copy link
Member Author

RunDevelopment commented Feb 13, 2019

This is just an idea for now but with ES6 tagged template literals we could make a function Prism.regex which will behave like Prism.patterns.build but has a nice syntax:

const foo = /\bfoo\b/;

Prism.regex`\w\s${foo}\s`; // returns /\w\s(?:\bfoo\b)/

// instead of
Prism.patterns.build(/\w\s<<0>>/, [foo]);

There a few drawbacks (flags, browser compatibility, no regex syntax highlighting).
The fact, that the tag approach does not use regex literals is both an advantage (no regex compile overhead) and a disadvantage (syntax check only during runtime, no syntax highlighting).

Edit: Flags can be declared using regex (no flags), regex.i, regex.m, and regex.im.

@RunDevelopment
Copy link
Member Author

Closed in favor of #2190.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants